package com.example.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * String 类型得缓存
     * @return
     */
    @RequestMapping("hello")
    public String hello(){
        redisTemplate.opsForValue().set("1", "张三");
        return (String) redisTemplate.opsForValue().get("1");
    }


    /**
     * list类型得缓存
     * @return
     */

    @GetMapping("list")
    public Object listRedis(){
        String key = "redis-list-key";
        String value = String.valueOf(System.currentTimeMillis() + 1);
        redisTemplate.opsForList().leftPush(key, value);
        redisTemplate.opsForList().leftPush(key, value);
        return redisTemplate.opsForList().leftPop(key);

    }
}
